//: -L+yaml


import tango.io.Stdout;


alias char	yaml_char_t ;

struct yaml_version_directive_t {
	int major;
	int minor;
}

struct yaml_tag_directive_t {
	yaml_char_t*	handle ;
	yaml_char_t*	prefix ;
}

enum yaml_encoding_t {
	YAML_ANY_ENCODING ,
	YAML_UTF8_ENCODING ,
	YAML_UTF16LE_ENCODING ,
	YAML_UTF16BE_ENCODING
}

enum yaml_break_t {
    YAML_ANY_BREAK,
    YAML_CR_BREAK,
    YAML_LN_BREAK,
    YAML_CRLN_BREAK
}

enum yaml_error_type_t {
    YAML_NO_ERROR,
    YAML_MEMORY_ERROR,
    YAML_READER_ERROR,
    YAML_SCANNER_ERROR,
    YAML_PARSER_ERROR,
    YAML_COMPOSER_ERROR,
    YAML_WRITER_ERROR,
    YAML_EMITTER_ERROR
}

struct yaml_mark_t {
    size_t	index;
    size_t	line;
    size_t	column;
}

enum yaml_scalar_style_t {
    YAML_ANY_SCALAR_STYLE,
    YAML_PLAIN_SCALAR_STYLE,
    YAML_SINGLE_QUOTED_SCALAR_STYLE,
    YAML_DOUBLE_QUOTED_SCALAR_STYLE,
    YAML_LITERAL_SCALAR_STYLE,
    YAML_FOLDED_SCALAR_STYLE
}

enum yaml_sequence_style_t {
    YAML_ANY_SEQUENCE_STYLE,
    YAML_BLOCK_SEQUENCE_STYLE,
    YAML_FLOW_SEQUENCE_STYLE
}

enum yaml_mapping_style_t {
    /** Let the emitter choose the style. */
    YAML_ANY_MAPPING_STYLE,

    /** The block mapping style. */
    YAML_BLOCK_MAPPING_STYLE,
    /** The flow mapping style. */
    YAML_FLOW_MAPPING_STYLE
/*    YAML_FLOW_SET_MAPPING_STYLE   */
}


enum yaml_token_type_t {
    /** An empty token. */
    YAML_NO_TOKEN,

    /** A STREAM-START token. */
    YAML_STREAM_START_TOKEN,
    /** A STREAM-END token. */
    YAML_STREAM_END_TOKEN,

    /** A VERSION-DIRECTIVE token. */
    YAML_VERSION_DIRECTIVE_TOKEN,
    /** A TAG-DIRECTIVE token. */
    YAML_TAG_DIRECTIVE_TOKEN,
    /** A DOCUMENT-START token. */
    YAML_DOCUMENT_START_TOKEN,
    /** A DOCUMENT-END token. */
    YAML_DOCUMENT_END_TOKEN,

    /** A BLOCK-SEQUENCE-START token. */
    YAML_BLOCK_SEQUENCE_START_TOKEN,
    /** A BLOCK-SEQUENCE-END token. */
    YAML_BLOCK_MAPPING_START_TOKEN,
    /** A BLOCK-END token. */
    YAML_BLOCK_END_TOKEN,

    /** A FLOW-SEQUENCE-START token. */
    YAML_FLOW_SEQUENCE_START_TOKEN,
    /** A FLOW-SEQUENCE-END token. */
    YAML_FLOW_SEQUENCE_END_TOKEN,
    /** A FLOW-MAPPING-START token. */
    YAML_FLOW_MAPPING_START_TOKEN,
    /** A FLOW-MAPPING-END token. */
    YAML_FLOW_MAPPING_END_TOKEN,

    /** A BLOCK-ENTRY token. */
    YAML_BLOCK_ENTRY_TOKEN,
    /** A FLOW-ENTRY token. */
    YAML_FLOW_ENTRY_TOKEN,
    /** A KEY token. */
    YAML_KEY_TOKEN,
    /** A VALUE token. */
    YAML_VALUE_TOKEN,

    /** An ALIAS token. */
    YAML_ALIAS_TOKEN,
    /** An ANCHOR token. */
    YAML_ANCHOR_TOKEN,
    /** A TAG token. */
    YAML_TAG_TOKEN,
    /** A SCALAR token. */
    YAML_SCALAR_TOKEN
} 


struct yaml_token_t {
	yaml_token_type_t	type;
	union {
		struct {
			yaml_encoding_t	encoding;
		} 
		struct {
			yaml_char_t *	alias_value;
		} 
		struct {
			yaml_char_t*	anchor_value;
		}
		struct {
			yaml_char_t*	tag_handle;
			yaml_char_t*	tag_suffix;
		}
		struct {
			yaml_char_t*  scalar_value;
			size_t		scalar_length;
			yaml_scalar_style_t	scalar_style;
		} 
		struct {
			int	major;
			int	minor;
		}
		struct {
			yaml_char_t* tag_directive_handle;
			yaml_char_t* tag_directive_prefix;
		}
	} 
	yaml_mark_t	start_mark;
	yaml_mark_t	end_mark;
} 

enum yaml_event_type_t {
	YAML_NO_EVENT,
	YAML_STREAM_START_EVENT,
	YAML_STREAM_END_EVENT,
	YAML_DOCUMENT_START_EVENT,
	YAML_DOCUMENT_END_EVENT,
	YAML_ALIAS_EVENT,
	YAML_SCALAR_EVENT,
	YAML_SEQUENCE_START_EVENT,
	YAML_SEQUENCE_END_EVENT,
	YAML_MAPPING_START_EVENT,
	YAML_MAPPING_END_EVENT
}

struct yaml_event_t {
	yaml_event_type_t	type;
	union {
		struct {
			yaml_encoding_t encoding;
		}
		struct {
			yaml_version_directive_t* version_directive;
			struct {
				yaml_tag_directive_t* tag_directives_start;
				yaml_tag_directive_t* tag_directives_end;
			}
			int	document_start_implicit;
		}
		struct {
			int	document_end_implicit;
		}
		struct {
			yaml_char_t* alias_anchor;
		}
		struct {
			yaml_char_t* scalar_anchor;
			yaml_char_t* scalar_tag;
			yaml_char_t* scalar_value;
			size_t  scalar_length;
			int  scalar_plain_implicit;
			int scalar_quoted_implicit;
			yaml_scalar_style_t scalar_style;
		}
		struct {
			yaml_char_t*	sequence_start_anchor;
			yaml_char_t*	sequence_start_tag;
			int	sequence_start_implicit;
			yaml_sequence_style_t  sequence_start_style;
		}

		struct {
			yaml_char_t*	mapping_start_anchor;
			yaml_char_t*	mapping_start_tag;
			int mapping_start_implicit;
			yaml_mapping_style_t	mapping_start_style;
		}
	}
	yaml_mark_t	start_mark;
	yaml_mark_t	end_mark;
} 

const char[] 
	YAML_NULL_TAG	= "tag:yaml.org,2002:null" , 
	YAML_BOOL_TAG	= "tag:yaml.org,2002:bool" ,
	YAML_STR_TAG	= "tag:yaml.org,2002:str" ,
	YAML_INT_TAG	= "tag:yaml.org,2002:int" ,
	YAML_FLOAT_TAG	=  "tag:yaml.org,2002:float" ,
	YAML_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp" ,
	YAML_SEQ_TAG	=  "tag:yaml.org,2002:seq" ,
	YAML_MAP_TAG	=  "tag:yaml.org,2002:map" ;
alias YAML_STR_TAG YAML_DEFAULT_SCALAR_TAG ;
alias YAML_SEQ_TAG YAML_DEFAULT_SEQUENCE_TAG ;
alias YAML_MAP_TAG YAML_DEFAULT_MAPPING_TAG ;


enum yaml_node_type_t {
	YAML_NO_NODE,
	YAML_SCALAR_NODE,
	YAML_SEQUENCE_NODE,
	YAML_MAPPING_NODE
}

alias	 int yaml_node_item_t ;

struct yaml_node_pair_t {
	int key;
	int value;
}

struct yaml_node_t {
	yaml_node_type_t type;
	yaml_char_t* tag;

	union {
		struct {
			yaml_char_t * scalar_value;
			size_t scalar_length;
			yaml_scalar_style_t scalar_style;
		}
		struct {
			struct {
				yaml_node_item_t * items_start;
				yaml_node_item_t * items_end;
				yaml_node_item_t * items_top;
			} 
			yaml_sequence_style_t sequence_style;
		}
		struct {
			struct {
				yaml_node_pair_t * pairs_start;
				yaml_node_pair_t * pairs_end;
				yaml_node_pair_t * pairs_top;
			} 
			yaml_mapping_style_t  mapping_style;
		}
	}
	yaml_mark_t start_mark;
	yaml_mark_t end_mark;
}

struct yaml_document_t {

	struct {
		yaml_node_t * nodes_start;
		yaml_node_t * nodes_end;
		yaml_node_t * nodes_top;
	}
	yaml_version_directive_t *version_directive;

	struct {
		yaml_tag_directive_t* tag_directives_start;
		yaml_tag_directive_t* tag_directives_end;
	}

	int start_implicit;
	int end_implicit;

	yaml_mark_t start_mark;
	yaml_mark_t end_mark;
}

extern(C){
	void yaml_token_delete(yaml_token_t*);
	int yaml_stream_start_event_initialize(yaml_event_t*, yaml_encoding_t);
	int yaml_document_start_event_initialize(yaml_event_t*,yaml_version_directive_t*, yaml_tag_directive_t*,yaml_tag_directive_t*, int);
	int yaml_document_end_event_initialize(yaml_event_t*, int);
	int yaml_alias_event_initialize(yaml_event_t*, yaml_char_t*);
	int yaml_scalar_event_initialize(yaml_event_t*, yaml_char_t *anchor, yaml_char_t*, yaml_char_t*, int, int, int, yaml_scalar_style_t);
	int yaml_sequence_start_event_initialize(yaml_event_t*,yaml_char_t*, yaml_char_t*, int,yaml_sequence_style_t);
	int yaml_sequence_end_event_initialize(yaml_event_t*);
	int yaml_mapping_start_event_initialize(yaml_event_t*,yaml_char_t*, yaml_char_t*, int,yaml_mapping_style_t);
	int yaml_mapping_end_event_initialize(yaml_event_t*);
	void yaml_event_delete(yaml_event_t*);
	
}

void main(){
	Stdout.formatln("{}", &yaml_token_delete);
	Stdout.formatln("{}", &yaml_stream_start_event_initialize);
	Stdout.formatln("{}", &yaml_document_start_event_initialize);
	
}